package csu.web.dining.web.servlet;

import csu.web.dining.domain.Item;
import csu.web.dining.domain.Order;
import csu.web.dining.service.CatalogService;
import csu.web.dining.service.OrderService;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;

public class ListOrdersFormServlet extends HttpServlet {
    private static final String LIST_ORDERS_FORM = "/WEB-INF/jsp/order/ListOrders.jsp";

    private OrderService orderService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        orderService = new OrderService();
        List<Order> ordersList = orderService.getOrdersByUsername(username);
        HttpSession session = req.getSession();
        session.setAttribute("ordersList", ordersList);
        req.getRequestDispatcher(LIST_ORDERS_FORM).forward(req, resp);
    }
}
